1 /**
2 * Copyright 2008 WebPhotos
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.webphotos.gui.component;
17
18 import javax.swing.Action;
19 import javax.swing.ImageIcon;
20 import javax.swing.JButton;
21 import net.sf.webphotos.action.AcaoToolbar;
22
23 /**
24 * <PRE>
25 * Base para geração de Botões iconificados
26 * (um símbolo visual no lugar de uma palavra para identificar o botão)
27 *
28 * Atualmente ele é base para quatro botões da tela principal do WebPhotos abaixo do
29 * espaço usado para por legenda e crédito.
30 * </PRE>
31 */
32 public class BotaoIcone extends JButton {
33
34 private static final Action acaoToolbar = new AcaoToolbar();
35 private String iconPrefix = "webfotos";
36 /**
37 * Constante que define a largura do Botão-Ícone
38 */
39 public static final int TAMANHOX = 24;
40 /**
41 * Constante que define a altura do Botão-Ícone
42 */
43 public static final int TAMANHOY = 24;
44 /**
45 * Parâmetro que define se o botão ira trabalhar com suas bordas de forma
46 * personalizada.
47 */
48 //protected static boolean botaoPersonalizado = Util.getConfig().getBoolean("BotoesPersonalizados");
49 protected static boolean botaoPersonalizado = false;
50
51 /**
52 * Construtor Padrão do Botão-Ícone.
53 */
54 public BotaoIcone() {
55
56 this.setActionCommand(iconPrefix);
57 this.setRolloverEnabled(true);
58 this.addActionListener(acaoToolbar);
59
60 this.setText("");
61
62 if (botaoPersonalizado) {
63 this.setContentAreaFilled(false);
64 this.setBorderPainted(false);
65 this.setFocusPainted(false);
66 }
67
68 this.setBounds(getX(), getY(), TAMANHOX, TAMANHOY);
69
70 this.setUpIcons(iconPrefix);
71
72 }
73
74 /**
75 * Retorna o Objeto do tipo {@link net.sf.webphotos.acao.AcaoToolbar}
76 * responsável pelas ações que todos os botões irão acessar.
77 *
78 * @return Objeto {@link net.sf.webphotos.acao.AcaoToolbar} atualmente em
79 * uso.
80 */
81 public static Action getAcaoToolbar() {
82 return acaoToolbar;
83 }
84
85 /**
86 * Retorna o Prefixo dos ícones em uso.
87 *
88 * @return String em uso.
89 */
90 public String getIconPrefix() {
91 return iconPrefix;
92 }
93
94 /**
95 * <PRE>
96 * Prefixo do nome dos 3 Ícones que serão usados nas bordas personalizadas.
97 * Exemplo:
98 *
99 * Com o prefixo icone1, temos:
100 *
101 * * icone1.gif - Padrão. apresentado durante toda a execução.
102 * * icone1over.gif - Apresentado quando o mouse passa sobre o botão.
103 * * icone1press.gif - Apresentado quando o mouse é pressionado.
104 * </PRE>
105 *
106 * @param iconPrefix A string que será usada.
107 */
108 public synchronized void setIconPrefix(String iconPrefix) {
109 this.iconPrefix = iconPrefix;
110 setUpIcons(iconPrefix);
111 }
112
113 /**
114 * @param iconPrefix Icon Set prefix
115 */
116 private void setUpIcons(String iconPrefix) {
117 this.setIcon(new ImageIcon(getClass().getResource("/icons/" + iconPrefix + ".gif")));
118 this.setActionCommand(iconPrefix);
119 if (botaoPersonalizado) {
120 this.setRolloverIcon(new ImageIcon(getClass().getResource("/icons/" + iconPrefix + "over.gif")));
121 this.setPressedIcon(new ImageIcon(getClass().getResource("/icons/" + iconPrefix + "press.gif")));
122 }
123 }
124 }